import { RangedWeaponEffects, MeleeWeaponEffects, ArmorEffects, PowerArmorEffects } from "./Effects";
import {randomChoice} from "./CommonUtils";

const groupedRangedWeaponEffects = groupBy(RangedWeaponEffects, 'level');
const groupedMeleeWeaponEffects = groupBy(MeleeWeaponEffects, 'level');
const groupedArmorEffects = groupBy(ArmorEffects, 'level')
const groupedPowerArmorEffects = groupBy(PowerArmorEffects, 'level')

function groupBy(arr, prop) {
    return arr.reduce((groups, item) => {
        if (item.disabled) {
            return groups;
        }
        const key = item[prop];
        (groups[key] = groups[key] || []).push(item);
        return groups;
    }, {});
}

export default function getNextEffects(masterType, type) {
    let groupedEffects;
    switch(masterType) {
        case 'ranged':
            groupedEffects = groupedRangedWeaponEffects
            break;
        case 'melee':
            groupedEffects = groupedMeleeWeaponEffects
            break;
        case 'armor':
            groupedEffects = groupedArmorEffects
            break
        case 'powerarmor':
            groupedEffects = groupedPowerArmorEffects
    }
    const effects = [];
    for (const level in groupedEffects) {
        effects.push(randomChoice(groupedEffects[level]));
    }
    return effects;
}